package cn.openea.perpartner.minrest.service;

import com.alibaba.fastjson.JSONObject;
import cn.openea.perpartner.common.core.utils.StringUtils;
import org.springframework.amqp.rabbit.AsyncRabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.concurrent.Future;


/**
 * @author Weird077
 * @description TODO
 * @date 2022-06-02 17:57
 */
@Service
public class RestService {
    @Value("${rabbitmq.extra.routing_key}")
    private String extraRoutingKey;
    @Value("${rabbitmq.extra.exchange}")
    private String extraExchange;
    @Autowired
    private AsyncRabbitTemplate asyncRabbitTemplate;
    public Future<Object> sendWithFixedReplay(String systemid, JSONObject obj) {
        if (StringUtils.isEmpty(systemid)){
            systemid = "rest";
        }
        String routingKey =  systemid + extraRoutingKey;
        String exchange = systemid + extraExchange;
        //根据routingKey将消息发送给exchange，exchange将消息分发到对应的队列
        return asyncRabbitTemplate.convertSendAndReceive(exchange,routingKey,obj);
    }
}
